package org.example.tms.controller;

import org.example.tms.config.AjaxResult;
import org.example.tms.mapper.EmpMapper;
import org.example.tms.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/report")
public class ReportController {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @GetMapping("/empGenderData")
    public AjaxResult empGenderData(){
        //Map<String,object>键-值对
        List<Map> genderList = empMapper.coutEmpGenderData();
        return AjaxResult.success(genderList);
    }
    @GetMapping("/empJobData")
    public AjaxResult empJobData(){
        List<Map<String,Object>> maps = empMapper.coutEmpJobData();
        List<String> jobList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        //键的封装，封装到jobList
        for (Map<String,Object> map : maps) {

            //废稿
//            Set<String> job = map.keySet();
//            jobList.addAll(job);
//            dateList.addAll(map.values());


            // 提取“职业”字段（字符串）
            String jobName = (String) map.get("职业");
            // 关键修正：先获取 Long 类型的 value，再转为 Integer
            Long countLong = (Long) map.get("value"); // count(*) 返回 Long
            Integer count = countLong.intValue(); // 转换为 Integer
            jobList.add(jobName);
            dataList.add(count);
        }
        //封装成响应数据样例
        Map<String,Object> map1 = new HashMap<>();
        map1.put("jobList",jobList);
        map1.put("dataList",dataList);
        return AjaxResult.success(map1);
    }
    @GetMapping("/studentDegreeData")
    public AjaxResult studentDegreeData(){
        List<Map> degreeList = studentMapper.coutStudentDegreeData();
        return AjaxResult.success(degreeList);

    }
    @GetMapping("/studentCountData")
    public AjaxResult studentCountData(){
        List<Map<String,Object>> maps = studentMapper.coutStudentData();
        List<String> clazzList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        for (Map<String,Object> map : maps) {
            String clazzName = (String) map.get("name");
            Long countLong = (Long) map.get("value");
            Integer count = countLong.intValue();
            clazzList.add(clazzName);
            dataList.add(count);

        }
        Map<String,Object> map1 = new HashMap<>();
        map1.put("clazzList",clazzList);
        map1.put("dataList",dataList);
        return AjaxResult.success(map1);

    }

}
